<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:camunda="http://camunda.org/schema/1.0/bpmn" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  targetNamespace="Examples">

  <process id="compensationProcess" isExecutable="true">

    <startEvent id="theStart" />
    <sequenceFlow id="flow5" sourceRef="theStart" targetRef="subProcess" />
    <subProcess id="subProcess">
      <startEvent id="theSubProcessStart" />
      <sequenceFlow id="flow6" sourceRef="theSubProcessStart" targetRef="innerTask" />
      <userTask id="innerTask" />
      <sequenceFlow id="flow7" sourceRef="innerTask" targetRef="theSubProcessEnd" />
      <endEvent id="theSubProcessEnd" />
      
      <!-- Compensation event on innerTask -->
      <boundaryEvent id="innerCompensation" attachedToRef="innerTask">
        <compensateEventDefinition />
      </boundaryEvent>
      <userTask id="innerAfterBoundaryTask" isForCompensation="true" />
      <association associationDirection="One" sourceRef="innerCompensation" targetRef="innerAfterBoundaryTask" />
    </subProcess>
    
    <!-- Boundary event on subprocess -->
    <boundaryEvent id="outerCompensation" attachedToRef="subProcess">
      <compensateEventDefinition />
    </boundaryEvent>
    <userTask id="outerAfterBoundaryTask" isForCompensation="true"/>

    <sequenceFlow id="flow8" sourceRef="subProcess" targetRef="taskAfterSubprocess" />
    <userTask id="taskAfterSubprocess" />
    <sequenceFlow id="flow2" sourceRef="taskAfterSubprocess" targetRef="fork" />
    
    <!-- a compensation throwing event concurrent to a user task -->
    <parallelGateway id="fork" />
    <sequenceFlow id="flow3" sourceRef="fork" targetRef="throwCompensate" />
    <intermediateThrowEvent id="throwCompensate">
      <compensateEventDefinition  />
    </intermediateThrowEvent>
    <sequenceFlow id="flow9" sourceRef="throwCompensate" targetRef="theEnd" />
    
    <sequenceFlow id="flow4" sourceRef="fork" targetRef="concurrentTask" />
    <userTask id="concurrentTask"/>
    <sequenceFlow id="flow10" sourceRef="concurrentTask" targetRef="theEnd" />
    <endEvent id="theEnd" />
    <association associationDirection="One" sourceRef="outerCompensation" targetRef="outerAfterBoundaryTask" />
  </process>

</definitions>